﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
namespace LHWebApp.Json
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class GetData : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string op = context.Request.Params["op"];
            if (string.IsNullOrEmpty(op))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                switch (op)
                {
                    case "GET_AREA":
                        {
                            string vid = context.Request.Params["vid"];
                            if (string.IsNullOrEmpty(vid))
                            {
                                context.Response.Write("{success: false}");
                            }
                            else
                            {
                                DataTable dt = Services.GetData(string.Format("SELECT ISNULL(FIXBOUND,'') FIXBOUND FROM VEHICLE WHERE VID={0}", vid)).Tables[0];
                                JSONHelper jsonHelp = new JSONHelper();
                                jsonHelp.success = true;
                                jsonHelp.totlalCount = dt.Rows.Count;
                                foreach (DataRow dr in dt.Rows)
                                {
                                    jsonHelp.singleInfo = dr["FIXBOUND"].ToString();
                                    jsonHelp.ItemOk();
                                    break;
                                }
                                context.Response.Write(jsonHelp.ToString());
                            }
                        }
                        break;
                    default:
                        context.Response.Write("{success: false}");
                        break;
                }
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
